package com.kuang.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author: Zhang Dongwei
 * Date: 2022/4/16 20:44
 */
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //this.getInitParameter();  获取初始化参数
        //this.getServletConfig();  获取Servlet配置
        //this.getServletContext(); 获取Servlet上下文
        ServletContext context = this.getServletContext();
        String username = "张冬伟"; // 数据
        context.setAttribute("username",username);//将一个数据保存到了ServletContext中,名字为：username，值为username
        System.out.println("Hello");
    }
}
